Shamelessly copied from https://www.techrepublic.com/article/how-to-run-an-ssh-connection-through-tor/
Install Tor on both client and server:
sudo apt-get install tor -yIn the server let’s edit tor’s config file
/etc/tor/torrc:
 sudo nano /etc/tor/torrcAt the bottom of that file, add this:
 HiddenServiceDir /var/lib/tor/ssh/
 HiddenServicePort 22Optional extra configurations (trade-off anonimity for better performance)
 SocksPort 0
 HiddenServiceNonAnonymousMode 1
 HiddenServiceSingleHopMode 1Ctrl+x to save and close file.
Restart Tor:
 sudo systemctl restart torIt will be in the file hostname in the previously
configured folder /var/lib/tor/ssh
sudo cat /var/lib/tor/ssh/hostnameYou should get something like riludi2kstjwmlzn.onion
torify ssh ... # replace the domain/ip with the .onion addressFor example:
torify ssh jack@riludi2kstjwmlzn.onionYou don’t need to remember the .onion address, you
can write an entry to your user’s ssh config file
~/.ssh/config:
nano ~/.ssh/configSet configuration:
Host serverTor
    User jack
    HostName riludi2kstjwmlzn.onion
    Port 22Now you can simply connect with:
torify ssh serverTor